import http from "./interceptor/interceptor";
import Config from "../utils/config.js";

// 登录
export const $login = (data) => {
  return http.request({
    url: "/api/miniapp/users/login",
    method: "POST",
    data,
    showLoading: true,
    needCheck: false,
  });
};

// 添加乘车人
export const $addPassenger = (data) => {
  return http.request({
    url: "/api/miniapp/users/passenger",
    method: "POST",
    data,
    showLoading: true,
    needCheck: true,
  });
};

// 编辑乘车人
export const $editPassenger = (data, id) => {
  return http.request({
    url: "/api/miniapp/users/passenger/" + id,
    method: "PUT",
    data,
    showLoading: true,
    needCheck: true,
  });
};

// 删除乘车人
export const $deletePassenger = (data, id) => {
  return http.request({
    url: "/api/miniapp/users/passenger/" + id,
    method: "DELETE",
    data,
    showLoading: true,
    needCheck: true,
  });
};

// 获取乘车人详情
export const $getPassengerDetail = (data, id) => {
  return http.request({
    url: "/api/miniapp/users/passenger/" + id,
    method: "GET",
    data,
    showLoading: true,
    needCheck: true,
  });
};

// 获取乘车人列表
export const $getPassenger = (data) => {
  return http.request({
    url: "/api/miniapp/users/passenger",
    method: "GET",
    data,
    showLoading: true,
    needCheck: true,
  });
};

// 发送验证码
export const $sendCode = (data) => {
  return http.request({
    url: "/api/miniapp/users/sendCode",
    method: "POST",
    data,
    showLoading: true,
    needCheck: true,
  });
};

// 修改手机号
export const $changePhone = (data) => {
  return http.request({
    url: "/api/miniapp/users",
    method: "PUT",
    data,
    showLoading: true,
    needCheck: true,
  });
};

// 出发城市查询
export const $departcities = (data) => {
  return http.request({
    url: "/api/base/departcities",
    method: "GET",
    data,
    showLoading: true,
    needCheck: false,
  });
};

// 查询出发站点
export const $saleStationsDepart = (data) => {
  return http.request({
    url: "/api/base/departstations",
    method: "GET",
    data,
    showLoading: true,
    needCheck: true,
  });
};

// 查询到达站点
export const $saleStationsDest = (data) => {
  return http.request({
    url: "/api/base/deststations",
    method: "GET",
    data,
    showLoading: true,
  });
};

// 查询班次列表
export const $saleSchedules = (data) => {
  return http.request({
    url: "/api/base/schedules",
    method: "GET",
    data,
    showLoading: true,
  });
};

// 用户订单列表查询
export const $userOrder = (data) => {
  return http.request({
    url: "/api/miniapp/orders",
    method: "GET",
    data,
    showLoading: true,
    needCheck: true,
    header: {
      "Content-Type": "application/x-www-form-urlencoded",
    },
  });
};

// 用户订单查询详情查询
export const $userOrderDetail = (data, id) => {
  return http.request({
    url: "/api/sale/orders/userOrder/" + id,
    method: "GET",
    data,
    showLoading: true,
    needCheck: true,
  });
};

// 用户取消订单
export const $cancelOrder = (data, id) => {
  return http.request({
    url: "/api/sale/orders/cancel/" + id,
    method: "POST",
    data,
    showLoading: true,
    needCheck: true,
  });
};

// 用户提交订单
export const $submitOrder = (data) => {
  return http.request({
    url: "/api/miniapp/orders",
    method: "POST",
    data,
    showLoading: true,
    needCheck: true,
  });
};

// 立即支付
export const $ordersPay = (data, id) => {
  return http.request({
    url: `/api/miniapp/orders/${id}/pay`,
    method: "POST",
    data,
    showLoading: true,
    needCheck: true,
  });
};

// 售票
export const $ordersSale = (data, id) => {
  return http.request({
    url: "/api/sale/orders/sale/" + id,
    method: "POST",
    data,
    showLoading: true,
    needCheck: true,
    loadingText: "售票中...",
  });
};

// 撤销订单
export const $ordersClose = (data, id) => {
  return http.request({
    url: "/api/miniapp/orders/" + id,
    method: "DELETE",
    data,
    showLoading: true,
    needCheck: true,
  });
};

// 部分退票退款
export const $orderslosePart = (data, id) => {
  return http.request({
    url: `/api/miniapp/orders/${id}/refund`,
    method: "POST",
    data,
    showLoading: true,
    needCheck: true,
  });
};
// 公告
export const $notice = (appId) => {
  return http.request({
    url: `/api/base/notices/${appId}`,
    method: "GET",
    showLoading: false,
    needCheck: true,
  });
};
// export default { // 默认全部导出  import api from '@/service/interceptor/interceptor'
// 	$login, // 登录
// 	$addPassenger, // 添加乘车人
// 	$saleStationsDepart, // 查询出发站点
// 	$saleStationsDest, // 查询到达站点
// 	$saleSchedules, // 查询班次列表
// }
